package controller;

import enums.SysInfoEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import pojo.ClassCourseM;
import pojo.paymentM;
import service.DesignClassCourseService;
import utils.ResultUtils;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;

@Controller
@RequestMapping("/design")
public class DesignClassCourseController {

    @Autowired
    DesignClassCourseService designClassCourseService;


    @RequestMapping(value = "/index")
    public String index(){
        return "/WEB-INF/view/classCourseM/classCourseM.jsp";
    }


    @RequestMapping(value = "/getClassCourse")
    @ResponseBody
    public List<ClassCourseM> getClassCourse(){
        System.out.println(designClassCourseService.getClassCourse());
        return designClassCourseService.getClassCourse();
    }

    @RequestMapping(value = "/getOne", method=RequestMethod.POST)
    @ResponseBody
    public List<ClassCourseM> getOne(Integer grade){

        return designClassCourseService.getOne(grade);
    }

    @RequestMapping("/toadd")
    public String toadd(){
        return "/WEB-INF/view/classCourseM/add.jsp";
    }

    @RequestMapping(value = "/addClassCourse",method = RequestMethod.POST)
    @ResponseBody
    public String addcourse(@Valid @RequestBody ClassCourseM classCourseM,HttpServletRequest request){
        Integer result = 0;
        try{
            result= designClassCourseService.DesignClassCourse(classCourseM);
        }catch (Exception e){
            request.setAttribute("result","班级课程录入错误错误");
            e.printStackTrace();
            return ResultUtils.addResult(result);
        }

        return ResultUtils.addResult(result);
    }

    @RequestMapping("/delete")
    public String delete(String id){
        designClassCourseService.delete(id);
        return "/demo/design/index";

    }

    @RequestMapping(value = "/getByArray")
    @ResponseBody
    public List<ClassCourseM> getByArray(@RequestParam(value = "currentPage",defaultValue = "1") Integer currentPage,
                                         @RequestParam(value = "size",defaultValue = "5") Integer size){
        List<ClassCourseM> classCourseMS =  designClassCourseService.getClassCourseByArray(currentPage, size);
//        map.put("number",userFeedbackDTOPage.getTotalElements());
        return classCourseMS;
    }

    @RequestMapping(value = "/getNumber")
    @ResponseBody
    public Integer getNumber(){
        List<ClassCourseM> classCourseMS = designClassCourseService.getClassCourse();
        return classCourseMS.size();
    }

}
